<?php
/**
 * Created by 荣耀电竞.
 * User: 林子彦 <278805354@qq.com>
 * Date: 2018/6/29 0029
 * Time: 9:59
 */

namespace App\FreeBird\Controllers\Home;

use App\Base\Controllers\Controller;
use App\FreeBird\Contracts\VipShopInterface;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;


class VipShopController extends Controller
{

    /**
     * vip 支付
     * @return VipShopInterface
     */
       public function getVipShopInterface(){
           return app()->make(VipShopInterface::class);
       }

      public function getVipshopList(Request $request){
           $where=function($query) use($request){
               $lid=$request->input("lid");
               $query->where("lid",$lid);
           };
       return $this->getVipShopInterface()->getListAll($where);
      }

    /**
     * 购买vip
     */
    public function vipBuy(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'pay_id' => 'required',
            'pay_type' => 'required',
        ], ["pay_id.required" => '支付Id',"pay_type.required" => '支付方式']);
        if ($validator->fails()) {
            //$error=$validator->errors()->getMessages();
            $this->throwValidatorException($validator);
        }
        $payType=$request->input("pay_type");
        if($payType==1){   //微信支付
            return $this->getVipShopInterface()->setUserBuyVip($request->except("token"));
        }
        if($payType==2){  //金币支付
            return $this->getVipShopInterface()->setUserScoreBuyVip($request->except("token"));
        }

    }

    public function vipBuyNotify(Request $request){
        $xml = file_get_contents('php://input');
        return $this->getVipShopInterface()->setVipBuyNotify($xml);
    }

}